package com.jule.teenpatti.mail.model;

import com.jule.core.jedis.StoredObj;
import com.jule.teenpatti.mail.dao.bean.MailConfigModel;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 可用的邮件配置
 */
@Data
@Slf4j
public class MailConfigMap extends StoredObj {
    private Map<Integer, MailConfigModel> allMail = new ConcurrentHashMap<>();

    /**
     * 添加邮件配置信息
     *
     * @param list
     */
    public void addItem(List<MailConfigModel> list) {
        Iterator<MailConfigModel> iter = list.iterator();
        while (iter.hasNext()) {
            MailConfigModel mailConfig = iter.next();
            allMail.put(mailConfig.getId(), mailConfig);
        }
    }

    /**
     * 添加邮件配置信息
     *
     * @param mailConfigModel
     */
    public void addItem(MailConfigModel mailConfigModel) {
        allMail.put(mailConfigModel.getId(), mailConfigModel);
        log.info("addItem"+mailConfigModel.toString());
    }

    public void del(int mailConfigId) {
        allMail.remove(mailConfigId);
    }

    public List<MailConfigModel> getAllMailConfig() {
        List<MailConfigModel> list = new ArrayList<>(allMail.size());
        Iterator<MailConfigModel> iter = allMail.values().iterator();
        while (iter.hasNext()) {
            MailConfigModel mailConfig = iter.next();
            list.add(mailConfig);
        }
        return list;
    }

}
